package com.ss.android.article.base.feature.detail.view;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.aa;
import com.bytedance.common.utility.b.ThreadPlus;
import com.ss.android.article.base.ui.BaseDialog;
import com.ss.android.article.browser.R;
import com.ss.android.image.BaseImageManager;
import com.ss.android.image.FrescoUtils;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.newmedia.util.AppUtil;

import java.io.File;

public final class SaveImageBottomDialog extends BaseDialog {
    BaseImageManager mBaseImageManager;
    String mImageUri;
    ImageInfo mImageInfo;
    private TextView d;
    private TextView e;
    private Resources mResources;

    public SaveImageBottomDialog(Activity activity, ImageInfo imageInfo) {
        super(activity);
        this.mResources = activity.getResources();
        this.mImageInfo = imageInfo;
        this.mBaseImageManager = new BaseImageManager(((Context) activity));
        if (this.mImageInfo != null) {
            this.mImageUri = this.mImageInfo.mUri;
        }
    }

    public SaveImageBottomDialog(Activity activity, String imageUri) {
        super(activity);
        this.mResources = activity.getResources();
        this.mImageUri = imageUri;
        this.mBaseImageManager = new BaseImageManager(activity);
    }

    static Activity a(SaveImageBottomDialog arg1) {
        return arg1.mActivity;
    }

    static Activity b(SaveImageBottomDialog arg1) {
        return arg1.mActivity;
    }

    static Activity c(SaveImageBottomDialog arg1) {
        return arg1.mActivity;
    }

    protected final void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(1);
        View v1 = LayoutInflater.from(this.mActivity).inflate(com.ss.android.article.browser.R.layout.hz, null);
        this.setContentView(v1);
        this.setCanceledOnTouchOutside(true);
        this.d = v1.findViewById(com.ss.android.article.browser.R.id.a92);
        this.d.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new ThreadPlus(new Runnable() {
                    @Override
                    public void run() {
                        String v0 = aa.md5(SaveImageBottomDialog.this.mImageUri);
                        File v1 = FrescoUtils.tryGetCacheFile(Uri.parse(SaveImageBottomDialog.this.mImageUri));
                        if (v1 != null && (v1.exists())) {
                            SaveImageBottomDialog.this.mBaseImageManager.b(SaveImageBottomDialog.c(SaveImageBottomDialog.this), v0, SaveImageBottomDialog.this.mImageUri);
                        } else if (SaveImageBottomDialog.this.mImageInfo == null) {
                            AppUtil.a(SaveImageBottomDialog.a(SaveImageBottomDialog.this), new ImageInfo(SaveImageBottomDialog.this.mImageUri, null), SaveImageBottomDialog.this.mBaseImageManager, true);
                        } else {
                            AppUtil.a(SaveImageBottomDialog.b(SaveImageBottomDialog.this), SaveImageBottomDialog.this.mImageInfo, SaveImageBottomDialog.this.mBaseImageManager, true);
                        }
                    }
                }, "savePic", true).start();
                if ((SaveImageBottomDialog.this.g()) && (SaveImageBottomDialog.this.isShowing())) {
                    SaveImageBottomDialog.this.dismiss();
                }
            }
        });
        this.e = v1.findViewById(com.ss.android.article.browser.R.id.a93);
        this.e.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View arg2) {
                if ((SaveImageBottomDialog.this.g()) && (SaveImageBottomDialog.this.isShowing())) {
                    SaveImageBottomDialog.this.dismiss();
                }
            }
        });
        int v0 = this.mResources.getDimensionPixelSize(R.dimen.hi);
        int v1_1 = this.mResources.getDimensionPixelSize(R.dimen.hg);
        Window v2 = this.getWindow();
        Display v3 = v2.getWindowManager().getDefaultDisplay();
        Point v4 = new Point();
        com.bytedance.common.b.b.a(v3, v4);
        int v6 = 80;
        int v5 = -2;
        if (v4.x <= v0 || v4.y <= v1_1 || !TTUtils.a(this.mActivity, v4.x, v4.y)) {
            v2.setLayout(-1, v5);
            v2.setGravity(v6);
        } else {
            v2.setLayout(v0, v5);
            v2.setGravity(17);
        }

        if (v2.getAttributes().gravity == v6) {
            v2.setWindowAnimations(R.style.jd);
        }
    }
}

